package com.feri.redromance01.service.impl;

import com.feri.redromance01.dao.ServicesDao;
import com.feri.redromance01.entity.Services;
import com.feri.redromance01.service.intf.ServicesService;
import com.feri.redromance01.util.StringUtil;
import com.feri.redromance01.vo.PageBean;
import com.feri.redromance01.vo.R;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * ┌─┐       ┌─┐
 * ┌──┘ ┴───────┘ ┴──┐
 * │                 │
 * │       ───       │
 * ███████───███████ │
 * │                 │
 * │       ─┴─       │
 * │                 │
 * └───┐         ┌───┘
 * │         │
 * │         │
 * │         │
 * │         └──────────────┐
 * │                        │
 * │                        ├─┐
 * │                        ┌─┘
 * │                        │
 * └─┐  ┐  ┌───────┬──┐  ┌──┘
 * │ ─┤ ─┤       │ ─┤ ─┤
 * └──┴──┘       └──┴──┘
 * 神兽保佑
 * 代码无BUG!
 *
 * @Author: 李南航
 * @date 2022/8/27 20:23
 * @project RedRomance
 * @Description:
 */
@org.springframework.stereotype.Service
public class ServicesServiceImpl implements ServicesService {
    @Autowired
    private ServicesDao dao;
    @Override
    public R save(Services services) {
        System.out.println(services);
        if(dao.save(services)>0){
            return R.ok();
        }else {
            return R.fail();
        }
    }

    @Override
    public R update(Services service) {
        if(dao.update(service)>0){
            return R.ok();
        }else {
            return R.fail();
        }
    }

    @Override
    public R delete(int ser_id) {
        if(dao.delete(ser_id)>0){
            return R.ok();
        }else {
            return R.fail();
        }
    }

    @Override
    public PageBean selectPage(String ser_name, int page, int limit) {
        if(StringUtil.isNotEmpty(ser_name)){
            ser_name="%"+ser_name+"%";
        }
        int start=(page-1)*limit;

        return PageBean.ok(dao.selectCount(ser_name),dao.selectPage(ser_name,start,limit));
    }
}
